home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / LConsoleAttachment / LConsoleAttachment.h < prev    next >
Encoding:
Text File  |  1995-03-12  |  4.5 KB  |  135 lines  |  [TEXT/CWIE]

  1. // LConsoleAttachment.h - Attachment which pumps events through SIOUX.
  2. /******************************************************************************\
  3. Copyright (c) 1995 by Ken Badertscher (KenBad@aol.com).  All Rights Reserved.
  4.  
  5. Permission to use, copy, modify, distribute and sell this software and its
  6. documentation for any purpose is hereby granted without fee, provided that
  7. the above copyright notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting documentation.
  9. Ken Badertscher makes no representations about the suitability of this software
  10. for any purpose.  It is provided "as is" without express or implied warranty.
  11.  
  12. USAGE NOTES:
  13.     This class is useful for PowerPlant apps that want to use a console window
  14.     for debugging info.  In your LApplication subclass constructor, add
  15.     an LConsoleAttachment like so:
  16.         AddAttachment(new LConsoleAttachment("\pMy Console",
  17.                                         LConsoleAttachment::kAutoClose,
  18.                                         LConsoleAttachment::kNoAskSave));
  19.     or use the handy AddConsoleAttachment macro to set up a default console.
  20.  
  21.     You need to do a couple of things to get the console window to coexist
  22.     peaceably with your PowerPlant app:
  23.     
  24.     1) Override AdjustCursor so that LEventDispatcher doesn't set an arrow
  25.     cursor when the cursor is over an active console window.  (LEventDispatcher
  26.     really should do this for you--oh well.)  This can be done like so:
  27.         void MyApp::AdjustCursor(const EventRecord &inMacEvent)
  28.         {
  29.             EventRecord e = inMacEvent;
  30.             if (LAttachable::ExecuteAttachments(msg_AdjustCursor, &e))
  31.                 inherited::AdjustCursor(inMacEvent);
  32.         }
  33.  
  34.     2) Use an StFlushSIOUX object in any function that writes to the console
  35.     to ensure that the console window scroller is properly updated.  As of
  36.     this writing, SIOUX doesn't properly update scrollbars when output streams
  37.     are flushed.  Here's an example:
  38.         void MyDebugFunction()
  39.         {
  40.             StFlushSIOUX flusher;
  41.             cout << "debugging information" << endl;
  42.         }
  43.  
  44.     That's all there is to it!
  45.  
  46.     Mail kudos & brickbats to KenBad@aol.com.
  47.  
  48. History:
  49.     95-10-31 kbad    Released it.  Happy Halloween!
  50.     95-10-30 kbad    Added command mapping to let SIOUX use app menus.
  51.     95-10-15 kbad    Added auto-close flag
  52.     95-03-12 kbad    Created
  53.  
  54. TODO:
  55. \******************************************************************************/
  56.  
  57. #pragma once
  58.  
  59. #ifndef LCONSOLEATTACHMENT_H
  60. #define LCONSOLEATTACHMENT_H
  61.  
  62. #include <LAttachment.h>
  63. #include <LCommander.h> // SCommandStatus
  64. #include <LString.h>
  65.  
  66. // Macro to set up a default console attachment.
  67. //
  68. #define AddConsoleAttachment() AddAttachment(&gConsoleAttachment,nil,false)
  69.  
  70. class StFlushSIOUX
  71. {
  72. /*============================================================================*\
  73.     SIOUX console flusher - forces SIOUX to update scrollbars when exiting
  74.     a scope.  Instantiate one of these in a function that does console output
  75.     to work around SIOUX bug where it doesn't update scroll bars until its
  76.     window is activated. 
  77. \*============================================================================*/
  78. public:
  79.     StFlushSIOUX() {}
  80.     ~StFlushSIOUX();
  81. };
  82.  
  83.  
  84. class LConsoleAttachment : public LAttachment
  85. {
  86. /*============================================================================*\
  87.     Attachment which pumps events through SIOUX.
  88. \*============================================================================*/
  89. public:
  90.     // I like my booleans to have meaningful names.
  91.         enum EAutoClose {kNoAutoClose, kAutoClose};
  92.         enum EAskSave {kNoAskSave, kAskSave};
  93.  
  94.     // Canonical members
  95.         LConsoleAttachment(StringPtr title=0, EAutoClose=kAutoClose,
  96.                             EAskSave=kNoAskSave);
  97. virtual ~LConsoleAttachment();
  98.  
  99. private:
  100.     // no copying
  101.         LConsoleAttachment(const LConsoleAttachment&);
  102.         LConsoleAttachment& operator=(const LConsoleAttachment&);
  103.  
  104. protected:
  105.     // Framework overrides
  106. virtual void ExecuteSelf(MessageT inMessage, void *ioParam);
  107.  
  108. private:
  109.     // Implementation
  110.         void FindCommandStatus(const SCommandStatus &status);
  111.  
  112.         void AdjustCursor(const EventRecord &inMacEvent);
  113.         void DispatchEvent(const EventRecord& inMacEvent);
  114.         void ObeyCommand(CommandT inCommand, void *ioParam);
  115.         Boolean CommandKeyEvent(CommandT inCommand, EventRecord& e);
  116.  
  117.         Boolean SIOUXIsFront();
  118.  
  119.         TString<Str255> mTitle;
  120.         Boolean mTitleSet;
  121.  
  122.         enum {kNumCommands = cmd_SelectAll+1};
  123.         Boolean mCommandsCached;
  124.         UInt32 mCommandKeyEvent[kNumCommands];
  125. };
  126.  
  127. // Default console attachment, useful if no customization is needed.
  128. //
  129. extern LConsoleAttachment gConsoleAttachment;
  130.  
  131. // LConsoleAttachment inlines
  132. //==============================================================================
  133.  
  134. #endif //ndef LCONSOLEATTACHMENT_H
  135.